home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Exchange
/
CD Exchange - Volume 1.iso
/
games
/
pd
/
chess
/
src.lha
/
src
/
amiga
/
amidsp.c
next >
Wrap
C/C++ Source or Header
|
1992-09-06
|
20KB
|
1,010 lines
/*
* amidsp.c - Amiga interface for GNUCHESS, based on
* nuxdsp.c - (new) ALPHA interface for CHESS
*
* Copyright (c) 1988,1989,1990 John Stanback
* Copyright (c) 1992 Free Software Foundation
* Copyright (c) 1992 Martin W. Scott
*
* This file is part of GNU CHESS.
*
* GNU Chess is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Chess is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Chess; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <ctype.h>
#include <signal.h>
#include <sys/types.h>
#include <stdarg.h>
#define BOARD_FOREGROUND 1
#define TEXT_FOREGROUND 6
#define INPUT_FOREGROUND 7
#if defined(__STDC__)
/* <stdlib.h> */
extern void *malloc (size_t);
extern void exit (int);
/* <string.h> */
extern char *strcat (char *, const char *);
extern int strcmp (const char *, const char *);
extern char *strcpy (char *, const char *);
/* <time.h> */
extern long int time (long int *);
#endif
#include "gnuchess.h"
#include "amiterm.h"
#include "draw.h"
extern short int sscore[];
extern short int pscore[2];
#define TAB (45)
/* coordinates within a square for the following are ([1,5],[1,3]) */
#define SQW (5)
#define SQH (3)
#define VIR_C(s) ((flag.reverse) ? 7-column(s) : column(s))
#define VIR_R(s) ((flag.reverse) ? 7-row(s) : row(s))
#define VSQ_X(x) ((flag.reverse) ? SQW + 1 - (x) : (x))
#define VSQ_Y(y) ((flag.reverse) ? SQH + 1 - (y) : (y))
#define Vblack(s) (!((VIR_C(s) + VIR_R(s)) % 2))
/* Squares swapped */
#define Vcoord(s,x,y) \
((SQW)*(VIR_C(s)))+(x),((SQH)*(7-VIR_R(s))+(y))
/* Squares and internal locations swapped */
#define VcoordI(s,x,y) \
((SQW)*(VIR_C(s)))+(VSQ_X(x)),((SQH)*(7-VIR_R(s))+(VSQ_Y(y)))
/* Squares and internal rows swapped */
#define VcoordR(s,x,y) \
((SQW)*(VIR_C(s)))+(x),((SQH)*(7-VIR_R(s))+(VSQ_Y(y)))
char Analysis[128] = "";
unsigned short int MV[MAXDEPTH];
int MSCORE;
char *DRAW;
extern char mvstr[4][6];
extern short Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
short PositionFlag = 0;
void TerminateSearch (int), Die (int);
#define OReverse standout
#define ONormal standend
cursoron()
{
leaveok(NULL, 0); /* cursor on... */
attron(INPUT_FOREGROUND);
printw("");
refresh();
}
cursoroff()
{
attron(TEXT_FOREGROUND);
leaveok(NULL, 1); /* ...cursor off */
}
/* max. of 3 parameters... */
ami_scanw(char *fmt, void *a1, void *a2, void *a3)/* aesthetic curses... */
{
int rv;
cursoron();
#ifdef I_WISH
rv = vscanw(fmt, (long *)ap);
#else
rv = scanw(fmt, a1, a2, a3);
#endif
cursoroff();
return rv;
}
void
Initialize (void)
{
signal (SIGINT, Die);
#ifndef AMIGA
signal (SIGQUIT, Die);
#endif
initscr ();
attron(TEXT_FOREGROUND);
leaveok(NULL, 1); /* ...cursor off */
gotoXY(22,12);
printw("Welcome to GNU CHESS. Initialising...");
refresh();
crmode ();
}
void
ExitChess (void)
{
#ifdef ALWAYSLIST
ListGame ();
#endif
refresh();
nocrmode ();
endwin ();
exit (0);
}
void
Die (int Sig)
{
char s[80];
signal (SIGINT, SIG_IGN);
#ifndef AMIGA
signal (SIGQUIT, SIG_IGN);
#endif
ShowMessage (CP[31]); /*Abort?*/
scanz ("%s", s);
if (stricmp (s, CP[210]) == 0) /*yes*/
ExitChess ();
signal (SIGINT, Die);
#ifndef AMIGA
signal (SIGQUIT, Die);
#endif
}
void
TerminateSearch (int Sig)
{
signal (SIGINT, SIG_IGN);
#ifndef AMIGA
signal (SIGQUIT, SIG_IGN);
#endif
if (!flag.timeout)
flag.musttimeout = true;
flag.bothsides = false;
signal (SIGINT, Die);
#ifndef AMIGA
signal (SIGQUIT, Die);
#endif
}
void
ShowLine (unsigned short int *bstline)
{
}
void
help (void)
{
ClrScreen ();
/*printz ("CHESS command summary\n");*/
#ifdef NON_GFX
printz (CP[40]);
printz ("----------------------------------------------------------------\n");
#else
attron(HILITE_PEN);
printz (CP[40]);
attron(TEXT_PEN);
#endif
/*printz ("g1f3 move from g1 to f3 quit Exit Chess\n");*/
printz (CP[158]);
/*printz ("Nf3 move knight to f3 beep turn %s\n", (flag.beep) ? "off" : "on");*/
printz (CP[86], (flag.beep) ? CP[92] : CP[93]);
/*printz ("a7a8q promote pawn to queen\n");*/
printz (CP[128], (flag.material) ? CP[92] : CP[93]);
/*printz ("o-o castle king side easy turn %s\n", (flag.easy) ? "off" : "on");*/
printz (CP[173], (flag.easy) ? CP[92] : CP[93]);
/*printz ("o-o-o castle queen side hash turn %s\n", (flag.hash) ? "off" : "on");*/
printz (CP[174], (flag.hash) ? CP[92] : CP[93]);
/*printz ("bd redraw board reverse board display\n");*/
printz (CP[130]);
/*printz ("list game to chess.lst book turn %s used %d of %d\n", (Book) ? "off" : "on", bookcount, BOOKSIZE);*/
printz (CP[170], (Book) ? CP[92] : CP[93], bookcount, BOOKSIZE);
/*printz ("undo undo last ply remove take back a move\n");*/
printz (CP[200]);
/*printz ("edit edit board force enter game moves\n");*/
printz (CP[153]);
/*printz ("switch sides with computer both computer match\n");*/
printz (CP[194]);
/*printz ("white computer plays white black computer plays black\n");*/
printz (CP[202]);
/*printz ("depth set search depth clock set time control\n");*/
printz (CP[149]);
/*printz ("hint suggest a move post turn %s principle variation\n", (flag.post) ? "off" : "on");*/
printz (CP[177], (flag.post) ? CP[92] : CP[93]);
/*printz ("save game to file get game from file\n");*/
printz (CP[188]);
/*printz ("random randomize play new start new game\n");*/
printz (CP[181]);
/*printz ("coords show coords rv reverse video\n");*/
printz (CP[144]);
#ifdef NON_GFX
printz (CP[192]);
#define INCREMENT 0
#else
#define INCREMENT -1
#endif
gotoXY (10, 20+INCREMENT);
printz (CP[47], ColorStr[computer]);
gotoXY (10, 21+INCREMENT);
printz (CP[97], ColorStr[opponent]);
gotoXY (10, 22+INCREMENT);
printz (CP[79], MaxResponseTime/100);
#ifdef NON_GFX
gotoXY (10, 23+INCREMENT);
printz (CP[59], (flag.easy) ? CP[93] : CP[92]);
#endif
gotoXY (40, 20+INCREMENT);
printz (CP[52], MaxSearchDepth);
gotoXY (40, 21+INCREMENT);
printz (CP[100], (dither) ? CP[93] : CP[92]);
gotoXY (40, 22+INCREMENT);
printz (CP[112], (flag.hash) ? CP[93] : CP[92]);
#ifdef NON_GFX
gotoXY (40, 23+INCREMENT);
printz (CP[73]);
gotoXY (10, 24+INCREMENT);
printz (CP[110], (TCflag) ? CP[93] : CP[92],
TimeControl.moves[white], TimeControl.clock[white] / 100, OperatorTime, MaxSearchDepth);
#else
gotoXY (10, 23+INCREMENT);
printz (CP[110], (TCflag) ? CP[93] : CP[92],
TimeControl.moves[white], TimeControl.clock[white] / 100, OperatorTime, MaxSearchDepth);
#endif
refresh ();
getch ();
ClrScreen ();
UpdateDisplay (0, 0, 1, 0);
}
void
EditBoard (void)
/*
* Set up a board position. Pieces are entered by typing the piece followed
* by the location. For example, Nf3 will place a knight on square f3.
*/
{
short a, r, c, sq, i;
char s[80];
flag.regularstart = false;
Book = false;
ClrScreen ();
UpdateDisplay (0, 0, 1, 0);
gotoXY (TAB, 3);
printz (CP[29]);
gotoXY (TAB, 4);
printz (CP[28]);
gotoXY (TAB, 5);
printz (CP[136]);
gotoXY (TAB, 7);
printz (CP[64]);
a = white;
do
{
gotoXY (TAB, 6);
printz (CP[60], ColorStr[a]); /*Editing %s*/
gotoXY (TAB + 24, 7);
ClrEoln ();
scanz ("%s", s);
if (s[0] == CP[28][0]) /*#*/
{
attron(BOARD_FOREGROUND);
for (sq = 0; sq < 64; sq++)
{
board[sq] = no_piece;
color[sq] = neutral;
DrawPiece (sq);
}